﻿using DAL.Register;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utils;

namespace DAL
{
   public class PagingDAL
    {
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public  DataTable Thequery(PageDto Model)
        {
            string sql = $@"SELECT {Model.details} FROM (select top {Model.line} * from {Model.tab} where {Model.column} not in (select top({Model.line} * {Model.start} - {Model.line}) {Model.column} from  {Model.tab})) as a
                         INNER JOIN {Model.tab1} as b
                          ON a.{Model.column}= b.{Model.column1}; ";
            return SQLHelper.Query(sql,null);
        }
        /// <summary>
        /// 获取页数
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public  DataTable Thetotal(PageDto Model)
        {
            string sql = $"select count({Model.column})/{Model.line} as count from {Model.tab}";
            return SQLHelper.Query(sql,null);
        }


        /// <summary>
        /// 三连
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public  DataTable Thequery3(PageDto Model)
        {
            string sql = $@"SELECT {Model.details} FROM (select top {Model.line} * from {Model.tab} where {Model.column} not in (select top({Model.line} * {Model.start} - {Model.line}) {Model.column} from  {Model.tab})) as a
                         INNER JOIN {Model.tab1}  b
                          ON a.{Model.column}= b.{Model.column1}
                          LEFT OUTER JOIN BookState  c
                          ON c.ID=b.State";
            //WHERE b.BookID like '%@BookId%'
            SqlParameter[] sqlp = {
            new SqlParameter("@BookId",Model.BookId),
            };
            return SQLHelper.Query(sql, null);
        }

    }
}
